package cn.com.idmy.base.util;


import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

import static java.lang.System.getProperty;
import static org.dromara.hutool.core.convert.ConvertUtil.toInt;

public class AppUtil {
    private static final Set<String> appKeys = new HashSet<>();

    public static void register(String appKey) {
        appKeys.add(appKey);
    }

    public static @NotNull Set<String> appKeys() {
        return Collections.unmodifiableSet(appKeys);
    }

    @NotNull
    public static String appKey() {
        return getProperty("app.key");
    }

    public static int appPost() {
        return toInt(getProperty("app.port"), 0);
    }

    @NotNull
    public static String env() {
        return getProperty("app.env");
    }

    public static boolean isProd() {
        return Objects.equals(env(), "prod");
    }

    public static boolean isTest() {
        return Objects.equals(env(), "test");
    }

    public static boolean isDev() {
        return Objects.equals(env(), "dev");
    }

    public static boolean isLocal() {
        return Objects.equals(env(), "local");
    }
}
